#!/bin/bash

curl -stderr "http://messages.finance.yahoo.com/mb/$1" |grep threadview |egrep -o "http*.+" |sed 's/"//g' |cat -n > tmpmsg1
curl -stderr "http://messages.finance.yahoo.com/mb/$1" |egrep " am<| pm<| ago<" |sed -e 's/<span>//g' -e 's/<\/span><\/a>//g' |cat -n > tmpmsg2
curl -stderr "http://messages.finance.yahoo.com/mb/$1" |egrep "user-href" |cut -d'>' -f2- |cut -d'<' -f1|awk '{print "@"$0}' |cat -n > tmpmsg3
join tmpmsg2 tmpmsg3 >tmpmsg4 
join tmpmsg1 tmpmsg4 >tmpmsg


cat tmpmsg|while read line
do
  export url=`echo $line |awk '{print $2}'`
  export time=`echo $line |awk '{print $3" "$4" "$5}'`
  export comments=`echo $line |cut -d'@' -f2`
  export sentiment=`curl -stderr $url |egrep -A 3 "Sentiment :" |egrep -i "Buy|Sell"`
  if [ "$sentiment" ];then
    echo  $time $sentiment "--"$comments
  fi
done
